package com.egao.common.module.student.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.egao.common.core.utils.PdfUtil;
import com.egao.common.module.company.utils.Job;
import com.egao.common.module.student.constants.StudentResumeConstants;
import com.egao.common.module.student.entity.Student;
import com.egao.common.module.student.entity.StudentResume;
import com.egao.common.module.student.entity.StudentResumeItem;
import com.egao.common.module.student.entity.vo.StudentResumeItemVO;
import com.egao.common.module.student.entity.vo.StudentResumeVO;
import com.egao.common.module.student.mapper.StudentMapper;
import com.egao.common.module.student.mapper.StudentResumeMapper;
import com.egao.common.module.student.service.StudentResumeItemService;
import com.egao.common.module.student.service.StudentResumeService;
import com.egao.common.module.system.constants.DictConstants;
import com.egao.common.module.system.entity.Dict;
import com.egao.common.module.system.service.DictService;
import com.egao.common.module.system.service.MajorService;
import com.itextpdf.text.*;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.exception.BusinessException;
import com.egao.common.core.exception.ParameterException;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 学生简历(StudentResume)表服务实现类
 *
 * @author dl
 * @since 2021-04-29 17:50:03
 */
@Service
@Slf4j
public class StudentResumeServiceImpl extends ServiceImpl<StudentResumeMapper, StudentResume> implements StudentResumeService {

    @Autowired
    private StudentMapper studentMapper;
    @Value("${minio.resumeDir}")
    private String resumeDir;
    @Autowired
    private MajorService majorService;
    @Autowired
    private DictService dictService;

    @Autowired
    private StudentResumeItemService studentResumeItemService;

    @Value("${minio.minioDir}")
    private String minioDir;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public JsonResult queryById(Integer id) {
        StudentResume studentResume = verifyStudentResume(id);
        return JsonResult.ok().setData(studentResume);
    }

    /**
     * 查询多条数据
     *
     * @param page 查询条件
     * @return 对象列表
     */
    @Override
    public List<StudentResume> listPage(PageParam<StudentResume> page) {
        return baseMapper.listPage(page);
    }

    /**
     * 新增数据
     *
     * @param studentResumeVO 实例对象
     * @return 实例对象
     */
    @Override
    public JsonResult insert(StudentResumeVO studentResumeVO) {
        verifyStudentResumeParam(studentResumeVO);

        if (studentResumeVO.getUserId() == null) {
            throw new ParameterException("用户信息不存在");
        }

        Student student = getByUserId(studentResumeVO.getUserId());
        if (student == null) {
            throw new ParameterException("学生信息不存在");
        }
        StudentResume studentResume = new StudentResume();
        BeanUtil.copyProperties(studentResumeVO, studentResume);
        studentResume.setStudentId(student.getId());

        if (save(studentResume)) {
            return JsonResult.ok("提交成功");
        }
        return JsonResult.error("提交失败");
    }

    /**
     * 修改数据
     *
     * @param studentResumeVO 实例对象
     * @return 实例对象
     */
    @Override
    public JsonResult update(StudentResumeVO studentResumeVO) {
        StudentResume studentResume = new StudentResume();
        BeanUtil.copyProperties(studentResumeVO, studentResume);
        StudentResume old = verifyStudentResume(studentResume.getId());
        if (old == null) {
            throw new BusinessException("学生简历不存在");
        }
        if (updateById(studentResume)) {
            return JsonResult.ok("提交成功");
        }
        return JsonResult.error("提交失败");
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public JsonResult deleteById(Integer id) {
        StudentResume old = verifyStudentResume(id);
        if (old == null) {
            throw new BusinessException("学生简历不存在");
        }
        if (removeById(old)) {
            return JsonResult.ok("提交成功");
        }
        return JsonResult.error("提交失败");
    }

    @Override
    public JsonResult saveResume(StudentResumeVO studentResumeVO) {
        if (studentResumeVO == null) {
            return JsonResult.error();
        }

        if (studentResumeVO.getStudentId() == null) {
            return JsonResult.error();
        }

        StudentResume studentResume = getStudentResumeByStudentId(studentResumeVO.getStudentId());
        // 没有标准简历
        // studentResumeVO = judgeAbilityByStudentResume(studentResumeVO);
        // 新增
        if (studentResume == null) {
            StudentResume resume = new StudentResume();
            BeanUtil.copyProperties(studentResumeVO, resume);
            save(resume);
            saveResumeItem(studentResumeVO.getList(), studentResumeVO.getStudentId());
            if (!studentResumeVO.getList().isEmpty()) {
                generateStudentResumePDF(studentResumeVO);
            }
        // 修改
        } else {
            BeanUtil.copyProperties(studentResumeVO, studentResume);
            updateById(studentResume);
            saveResumeItem(studentResumeVO.getList(), studentResumeVO.getStudentId());
            if (!CollectionUtil.isEmpty(studentResumeVO.getList())) {
                generateStudentResumePDF(studentResumeVO);
            }
        }
        return JsonResult.ok();
    }

    private void saveResumeItem(List<StudentResumeItemVO> resumeItemVOList, Integer studentId) {
        if (resumeItemVOList == null) {
            return;
        }
        QueryWrapper<StudentResumeItem> qr = new QueryWrapper<>();
        qr.eq("student_id", studentId);
        studentResumeItemService.remove(qr);
        List<StudentResumeItem> resumeItemList = new ArrayList<>();
        for (StudentResumeItemVO item : resumeItemVOList) {
            StudentResumeItem studentResumeItem = new StudentResumeItem();
            studentResumeItem.setStudentId(studentId);
            BeanUtil.copyProperties(item, studentResumeItem);
            resumeItemList.add(studentResumeItem);
        }
        studentResumeItemService.saveBatch(resumeItemList);
    }

    @Override
    public StudentResume queryByStudentId(Integer studentId) {
        return getStudentResumeByStudentId(studentId);
    }

    /**
     * 检查学生简历是否存在
     *
     * @param id 学生简历编号
     * @return StudentResume 学生简历
     */
    private StudentResume verifyStudentResume(Integer id) {
        if (id == null) {
            throw new ParameterException("学生简历编号为空");
        }

        StudentResume studentResume = baseMapper.selectById(id);
        if (studentResume == null) {
            throw new BusinessException("学生简历不存在");
        }
        return studentResume;
    }

    /**
     * 检查学生简历参数
     *
     * @param studentResumeVO 学生简历
     */
    private void verifyStudentResumeParam(StudentResumeVO studentResumeVO) {
        if (studentResumeVO == null) {
            throw new ParameterException("学生简历为空");
        }
        if (studentResumeVO.getStudentId() == null) {
            throw new ParameterException("学生编号为空");
        }
    }

    /**
     * 通过学生编号查询学生简历
     * @param studentId
     * @return
     */
    private StudentResume getStudentResumeByStudentId(Integer studentId) {
        return baseMapper.selectOne(new QueryWrapper<StudentResume>().eq("student_id", studentId).last("limit 1").orderByDesc("create_time"));
    }

    /**
     * 通过学生填写简历情况判断能力完成情况
     * @param studentResumeVO 学生简历
     * @return
     */
    private StudentResumeVO judgeAbilityByStudentResume(StudentResumeVO studentResumeVO) {
        // 基本素质 对应自我评价
//        if (StrUtil.isNotBlank(studentResumeVO.getEvaluation())) {
//            studentResumeVO.setBasicAbility(StudentResumeConstants.ABILITY_YES);
//        } else {
//            studentResumeVO.setBasicAbility(StudentResumeConstants.ABILITY_NO);
//        }
//        // 专业能力 获取了哪些证书、是否有发表论文、专业成绩
//        if (StrUtil.isNotBlank(studentResumeVO.getCertificateInside()) || StrUtil.isNotBlank(studentResumeVO.getMajorAchievement())) {
//            studentResumeVO.setMajorAbility(StudentResumeConstants.ABILITY_YES);
//        } else {
//            studentResumeVO.setMajorAbility(StudentResumeConstants.ABILITY_NO);
//        }
//        // 基础能力 等级、证书
//        if (StrUtil.isNotBlank(studentResumeVO.getForeignLanguages()) || StrUtil.isNotBlank(studentResumeVO.getBonus())) {
//            studentResumeVO.setBasicAbility(StudentResumeConstants.ABILITY_YES);
//        } else {
//            studentResumeVO.setBasicAbility(StudentResumeConstants.ABILITY_NO);
//        }
//        // 学习能力 奖学金
//        if (StudentResumeConstants.RESUME_TYPE_CERTIFICATE.equals(studentResumeVO.getCertificateInside()) || StudentResumeConstants.RESUME_TYPE_CERTIFICATE.equals(studentResumeVO.getCertificateOutside())) {
//            studentResumeVO.setStudyAbility(StudentResumeConstants.ABILITY_YES);
//        } else {
//            studentResumeVO.setStudyAbility(StudentResumeConstants.ABILITY_NO);
//        }
//        // 实践能力 是否具有实践经历
//        if (StudentResumeConstants.RESUME_TYPE_PRACTICE.equals(studentResumeVO.getPracticeInside()) || StudentResumeConstants.RESUME_TYPE_PRACTICE.equals(studentResumeVO.getPracticeOutside())) {
//            studentResumeVO.setPracticeAbility(StudentResumeConstants.ABILITY_YES);
//        } else {
//            studentResumeVO.setPracticeAbility(StudentResumeConstants.ABILITY_NO);
//        }
//        // 组织协调能力、实践能力  是否是党员或者学生干部
//        if (StudentResumeConstants.RESUME_TYPE_PRACTICE.equals(studentResumeVO.getCadre())) {
//            studentResumeVO.setOrganizeAbility(StudentResumeConstants.ABILITY_YES);
//        } else {
//            studentResumeVO.setOrganizeAbility(StudentResumeConstants.ABILITY_NO);
//        }
        // 创新能力 是否参加过科技活动、课外比赛
        return studentResumeVO;
    }

    /**
     * 查询学生基本信息
     * @param userId
     * @return
     */
    private Student getByUserId(Integer userId) {
        return studentMapper.selectOne(new QueryWrapper<Student>().eq("user_id", userId).last("limit 1"));
    }


    private void generateStudentResumePDF(StudentResumeVO studentResumeVO) {
        Student student = studentMapper.selectById(studentResumeVO.getStudentId());
        String path = resumeDir + "\\resume\\" + student.getId() + "\\";

        Font defaultFont = FontFactory.getFont(FontFactory.HELVETICA, 22, Font.BOLD);

        try {
            // 文件夹不存在就新建
            File file = new File(path);
            if (!file.isDirectory()) {
                file.mkdirs();
            }

            //创建文档
            com.itextpdf.text.Document document = new Document(PageSize.A4,5, 5, 36, 36);
            //设置文档保存路径
            PdfWriter.getInstance(document, new FileOutputStream(path + "resume.pdf"));
            document.open();

            // 设置title
            Paragraph title = new Paragraph(18f, "个人简历", PdfUtil.myfont(22, Font.BOLD));
            // Paragraph title = new Paragraph(18f, "个人简历", defaultFont);
            title.setAlignment(Element.ALIGN_CENTER);
            document.add(title);
            document.add(PdfUtil.blankRow(30));

            //基本信息
            PdfPTable tbBaseInfo = new PdfPTable(2);
            PdfPCell cell11 = new PdfPCell(new Paragraph(student.getXm(), PdfUtil.myfont(18,Font.NORMAL)));
            cell11.setBorder(0);
            //cell11.setPaddingTop(5);
            cell11.setPaddingBottom(10);
            cell11.setPaddingLeft(15);


            String headImgPath = studentResumeVO.getPhoto();
            String[] imgSplit = headImgPath.split("9000");
            String img = minioDir + imgSplit[1];
            Image headImg = Image.getInstance(img);

            //设置每列宽度比例
            int width11[] = {15,85};
            tbBaseInfo.setWidths(width11);
            tbBaseInfo.getDefaultCell().setBorder(0);
            PdfPCell cellHimg=new PdfPCell();
            cellHimg.setBorder(0);
            cellHimg.setImage(headImg);
            cellHimg.setColspan(1);//合并单元格
            cellHimg.setRowspan(3);
            tbBaseInfo.addCell(cellHimg);
            tbBaseInfo.addCell(cell11);
            Date birthday = student.getCsrq();
            String area = dictService.cacheLabel(DictConstants.TYPE_SYSZD, student.getSyszd());
            String sex = dictService.cacheLabel(DictConstants.TYPE_XB, student.getXb());
            String t = "";
            if (StudentResumeConstants.VIEW_YES.equals(studentResumeVO.getIsView())) {
                t = dictService.cacheLabel(DictConstants.TYPE_ZZMM, student.getZzmm());
            }
            PdfPCell cell12 = new PdfPCell(new Paragraph(sex+PdfUtil.splitVline+ DateUtil.format(birthday, DatePattern.NORM_DATE_PATTERN) +PdfUtil.splitVline+area+PdfUtil.splitVline+t, PdfUtil.myfont(12,Font.NORMAL)));
            cell12.setPaddingBottom(5);
            cell12.setPaddingLeft(15);
            cell12.setBorder(0);
            tbBaseInfo.addCell(cell12);
            PdfPCell cell13 = new PdfPCell(new Paragraph(student.getMobile()+PdfUtil.splitVline+student.getEmail(),PdfUtil.myfont(12,Font.NORMAL)));
            cell13.setBorder(0);
            cell13.setPaddingLeft(15);
            tbBaseInfo.addCell(cell13);
            document.add(tbBaseInfo);

            //加入空行
            document.add(PdfUtil.blankRow());

            //工作经历
            document.add(PdfUtil.add_headtitle_1("工作经历"));
            document.add(PdfUtil.blankRow(5));
            //工作经验 主体 Begin
            for (StudentResumeItemVO item : studentResumeVO.getList()) {
                if (StrUtil.isNotBlank(item.getA1()) && item.getA1().contains("~")) {
                    item.setA1(item.getA1().replace("~", "至"));
                }
                // 工作经历：
                if (StudentResumeConstants.RESUME_ITEM_TYPE_1.equals(item.getType())) {
                    PdfUtil.add_workExpTable(document, item, "1");
                }
            }

            document.add(PdfUtil.add_headtitle_1("项目经历"));
            document.add(PdfUtil.blankRow(5));


            for (StudentResumeItemVO item : studentResumeVO.getList()) {
                // 项目经历：
                if (StudentResumeConstants.RESUME_ITEM_TYPE_2.equals(item.getType())) {
                    PdfUtil.add_workExpTable(document, item, "0");
                }
            }
            int i3 = 0;
            for (StudentResumeItemVO item : studentResumeVO.getList()) {
                // 教育背景
                if (StudentResumeConstants.RESUME_ITEM_TYPE_3.equals(item.getType())) {
                    if (i3 == 0) {
                        document.add(PdfUtil.blankRow());
                        //资格证书
                        document.add(PdfUtil.add_headtitle_1("教育背景"));
                    }
                    PdfUtil.add_eduExpTable(document, item);
                    i3++;
                }
            }
            int i4 = 0;
            for (StudentResumeItemVO item : studentResumeVO.getList()) {
                // 校内荣誉
                if (StudentResumeConstants.RESUME_ITEM_TYPE_4.equals(item.getType())) {
                    if (i4 == 0) {
                        document.add(PdfUtil.blankRow());
                        //资格证书
                        document.add(PdfUtil.add_headtitle_1("获奖情况"));
                    }
                    PdfUtil.add_trainExpTable(document, item);
                    i4++;
                }
            }
            document.add(PdfUtil.add_headtitle_1("校内职务"));
            for (StudentResumeItemVO item : studentResumeVO.getList()) {
                // 校内职务
                if (StudentResumeConstants.RESUME_ITEM_TYPE_5.equals(item.getType())) {
                    PdfUtil.addPosition(document, item);
                }
            }
            int i6 = 0;
            for (StudentResumeItemVO item : studentResumeVO.getList()) {
                // 技能/语言
                if (StudentResumeConstants.RESUME_ITEM_TYPE_6.equals(item.getType())) {
                    if (i6 == 0) {
                        document.add(PdfUtil.blankRow());
                        //技能/语言
                        document.add(PdfUtil.add_headtitle_1("技能/语言"));
                    }

                    String[] a1s = item.getA1().split(",");
                    Dict dict = dictService.getByParent("inten_skill", 0, a1s[0]);
                    Dict dict1 = dictService.getByParent("inten_skill", dict.getId(), a1s[1]);
                    item.setA1(dict.getLabel() + " - " + dict1.getLabel());
                    PdfUtil.add_majorSkillExpTable(document, item);
                    i6 ++;
                }
            }
            int i7 = 0;
            for (StudentResumeItemVO item : studentResumeVO.getList()) {
                // 证书
                if (StudentResumeConstants.RESUME_ITEM_TYPE_7.equals(item.getType())) {
                    if (i7 ==0) {
                        document.add(PdfUtil.blankRow());
                        //资格证书
                        document.add(PdfUtil.add_headtitle_1("资格证书"));
                    }
                    String[] a2s = item.getA2().split(",");
                    Dict dict = dictService.getByParent("iten_certificate", 0, a2s[0]);
                    Dict dict1 = dictService.getByParent("iten_certificate", dict.getId(), a2s[1]);
                    item.setA2(dict.getLabel() + " - " + dict1.getLabel());
                    PdfUtil.add_certExpTable(document, item);
                    i7++;
                }
            }
            if (StrUtil.isNotBlank(studentResumeVO.getEvaluation())) {
                document.add(PdfUtil.blankRow());
                document.add(PdfUtil.blankRow(5));
                document.add(PdfUtil.add_headtitle_1("自我评价"));
                document.add(PdfUtil.blankRow(5));
                PdfUtil.addEvaluation(document, studentResumeVO.getEvaluation());
            }

            document.close();
            System.out.println("创建成功");


        } catch (Exception e) {
            e.printStackTrace();
        }

    }



    /**
     * 生成学生简历word
     * @param studentResume
     */
    private void generationResume(StudentResume studentResume) {

        System.out.println(studentResume);

        Student student = studentMapper.selectById(studentResume.getStudentId());
        String path = resumeDir + "\\resume\\" + student.getId() + "\\";

        try {
            // 文件夹不存在就新建
            File file = new File(path);
            if (!file.isDirectory()) {
                file.mkdirs();
            }

            XWPFDocument document = new XWPFDocument();
            FileOutputStream out = new FileOutputStream(new File(path + "resume.docx"));
            //添加标题
            XWPFParagraph title = document.createParagraph();
            //设置段落居中
            title.setAlignment(ParagraphAlignment.CENTER);

            XWPFRun tr = title.createRun();
            tr.setText("个人简历");
            tr.setColor("000000");
            tr.setFontSize(20);
            tr.setFontFamily("黑体");

            //换行
            XWPFParagraph br1 = document.createParagraph();
            XWPFRun pr1 = br1.createRun();
            pr1.setText("\r");

            //基本信息表格
            XWPFTable infoTable = document.createTable();
            //去表格边框
            infoTable.getCTTbl().getTblPr().unsetTblBorders();

            //列宽自动分割
            CTTblWidth infoTableWidth = infoTable.getCTTbl().addNewTblPr().addNewTblW();
            infoTableWidth.setType(STTblWidth.DXA);
            infoTableWidth.setW(BigInteger.valueOf(9072));

            int height = 400;
            //表格第一行
            XWPFTableRow row1 = infoTable.getRow(0);
            row1.setHeight(height);
            row1.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row1.getCell(0).setText("姓名");
            XWPFTableCell row12 = row1.addNewTableCell();
            row12.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row12.setText(student.getXm());

            //表格第二行
            XWPFTableRow row2 = infoTable.createRow();
            row2.setHeight(height);
            row2.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row2.getCell(0).setText("年龄");
            row2.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row2.getCell(1).setText(String.valueOf(IdcardUtil.getAgeByIdCard(student.getSfzhm())));

            //表格第三行
            XWPFTableRow row3 = infoTable.createRow();
            row3.setHeight(height);
            row3.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row3.getCell(0).setText("专业");
            row3.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row3.getCell(1).setText(majorService.getByCode(student.getCollegeCode(), student.getMajorCode()).getName());

            //表格第四行
            XWPFTableRow row4 = infoTable.createRow();
            row4.setHeight(height);
            row4.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row4.getCell(0).setText("电话");
            row4.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row4.getCell(1).setText(student.getMobile());

            //表格第五行
            XWPFTableRow row5 = infoTable.createRow();
            row5.setHeight(height);
            row5.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row5.getCell(0).setText("邮箱");
            row5.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row5.getCell(1).setText(student.getEmail());


            //表格第六行
            XWPFTableRow row6 = infoTable.createRow();
            row6.setHeight(height);
            row6.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row6.getCell(0).setText("政治面貌");
            row6.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            row6.getCell(1).setText(dictService.cacheLabel(DictConstants.TYPE_ZZMM, student.getZzmm()));

            // 是否担任过班干部
//            if (StudentResumeConstants.ABILITY_YES.equals(studentResume.getCadre())) {
//                XWPFTableRow row7 = infoTable.createRow();
//                row7.setHeight(height);
//                row7.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
//                row7.getCell(0).setText("是否担任过班干部");
//                row7.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
//                row7.getCell(1).setText("是");
//            }
//
//            if (StrUtil.isNotBlank(studentResume.getBonus())) {
//                XWPFTableRow row8 = infoTable.createRow();
//                row8.setHeight(height);
//                row8.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
//                row8.getCell(0).setText("获奖经历");
//                row8.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
//                String[] arr = studentResume.getBonus().split(",");
//                StringBuilder sr = new StringBuilder();
//                for (String s : arr) {
//                    // 其他
//                    if ("3".equals(s)) {
//                        sr.append(StudentResumeConstants.getBonusLabel(s)).append("：" + studentResume.getBonusText()).append("、");
//                    } else {
//                        sr.append(StudentResumeConstants.getBonusLabel(s)).append("、");
//                    }
//                }
//                sr.deleteCharAt(sr.lastIndexOf("、"));
//                row8.getCell(1).setText(sr.toString());
//            }


            //段落
            XWPFParagraph p2 = document.createParagraph();
            p2.setSpacingLineRule(LineSpacingRule.AUTO);
            XWPFRun run = p2.createRun();

            run.setText("外语等级");
            run.setFontSize(11);
            run.setBold(true);

            // 外语等级
//            if (StrUtil.isNotBlank(studentResume.getForeignLanguages())) {
//                String[] arr = studentResume.getForeignLanguages().split(",");
//
//                for (String s : arr) {
//                    StringBuilder sr = new StringBuilder();
//                    sr.append(StudentResumeConstants.getForeignLanguagesLabel(s)).append("：");
//                    XWPFParagraph p3 = document.createParagraph();
//                    XWPFRun r3 = p3.createRun();
//                    r3.setFontSize(9);
//                    switch (s) {
//                        case "1": {
//                            String[] array = studentResume.getEnglishLevel().split(",");
//                            for (String code : array) {
//                                sr.append(StudentResumeConstants.getEnglishLevelLabel(code)).append("、");
//                            }
//                            sr.deleteCharAt(sr.lastIndexOf("、"));
//                            r3.setText(sr.toString());
//                            break;
//                        }
//                        case "2": {
//                            String[] array = studentResume.getFrenchLevel().split(",");
//                            for (String code : array) {
//                                sr.append(StudentResumeConstants.getFrenchLevelLabel(code)).append("、");
//                            }
//                            sr.deleteCharAt(sr.lastIndexOf("、"));
//                            r3.setText(sr.toString());
//                            break;
//                        }
//                        case "3": {
//                            String[] array = studentResume.getRussianLevel().split(",");
//                            for (String code : array) {
//                                sr.append(StudentResumeConstants.getFrenchLevelLabel(code)).append("、");
//                            }
//                            sr.deleteCharAt(sr.lastIndexOf("、"));
//                            r3.setText(sr.toString());
//                            break;
//                        }
//                        case "4": {
//                            String[] array = studentResume.getArabicLevel().split(",");
//                            for (String code : array) {
//                                sr.append(StudentResumeConstants.getArabicLevelLabel(code)).append("、");
//                            }
//                            sr.deleteCharAt(sr.lastIndexOf("、"));
//                            r3.setText(sr.toString());
//                            break;
//                        }
//                        case "5": {
//                            String[] array = studentResume.getSpanishLevel().split(",");
//                            for (String code : array) {
//                                sr.append(StudentResumeConstants.getFrenchLevelLabel(code)).append("、");
//                            }
//                            sr.deleteCharAt(sr.lastIndexOf("、"));
//                            r3.setText(sr.toString());
//                            break;
//                        }
//                        case "6": {
//                            sr.append(studentResume.getForeignText());
//                            r3.setText(sr.toString());
//                            break;
//                        }
//                    }
//                }
//            }
//
//            // 专业成绩
//            if (StrUtil.isNotBlank(studentResume.getMajorAchievement())) {
//                //专业成绩
//                XWPFParagraph p3 = document.createParagraph();
//                p3.setSpacingLineRule(LineSpacingRule.AUTO);
//                XWPFRun run3 = p3.createRun();
//
//                run3.setText("专业成绩");
//                run3.setFontSize(11);
//                run3.setBold(true);
//
//                XWPFParagraph p4 = document.createParagraph();
//                XWPFRun pr4 = p4.createRun();
//                pr4.setFontSize(9);
//                pr4.setText(studentResume.getMajorAchievement().replaceAll("\\n","\r"));
//            }
//            // 获得证书
//            if (StudentResumeConstants.ABILITY_YES.equals(studentResume.getCertificateInside()) || StudentResumeConstants.ABILITY_YES.equals(studentResume.getCertificateOutside())) {
//                //获得证书
//                XWPFParagraph p3 = document.createParagraph();
//                p3.setSpacingLineRule(LineSpacingRule.AUTO);
//                XWPFRun run3 = p3.createRun();
//
//                run3.setText("获得证书");
//                run3.setFontSize(11);
//                run3.setBold(true);
//            }
//            if (StudentResumeConstants.ABILITY_YES.equals(studentResume.getCertificateInside())) {
//                XWPFParagraph p4 = document.createParagraph();
//                XWPFRun pr4 = p4.createRun();
//                pr4.setFontSize(9);
//                pr4.setText(studentResume.getCertificateInsideText().replaceAll("\\n","\r"));
//            }
//
//            if (StudentResumeConstants.ABILITY_YES.equals(studentResume.getCertificateOutside())) {
//                XWPFParagraph p4 = document.createParagraph();
//                XWPFRun pr4 = p4.createRun();
//                pr4.setFontSize(9);
//                pr4.setText(studentResume.getCertificateOutsideText().replaceAll("\\n","\r"));
//            }
//
//            // 社会实践
//            if (StudentResumeConstants.ABILITY_YES.equals(studentResume.getPracticeInside()) || StudentResumeConstants.ABILITY_YES.equals(studentResume.getPracticeOutside())) {
//                //社会实践
//                XWPFParagraph p3 = document.createParagraph();
//                p3.setSpacingLineRule(LineSpacingRule.AUTO);
//                XWPFRun run3 = p3.createRun();
//
//                run3.setText("社会实践");
//                run3.setFontSize(11);
//                run3.setBold(true);
//            }
//            if (StudentResumeConstants.ABILITY_YES.equals(studentResume.getPracticeInside())) {
//                XWPFParagraph p4 = document.createParagraph();
//                XWPFRun pr4 = p4.createRun();
//                pr4.setFontSize(9);
//                pr4.setText(studentResume.getPracticeInsideText().replaceAll("\\n","\r"));
//            }
//            if (StudentResumeConstants.ABILITY_YES.equals(studentResume.getPracticeOutside())) {
//                XWPFParagraph p4 = document.createParagraph();
//                XWPFRun pr4 = p4.createRun();
//                pr4.setFontSize(9);
//                pr4.setText(studentResume.getPracticeOutsideText().replaceAll("\\n","\r"));
//            }
//            // 自我评价
//            if (StrUtil.isNotBlank(studentResume.getEvaluation())) {
//                //社会实践
//                XWPFParagraph p3 = document.createParagraph();
//                p3.setSpacingLineRule(LineSpacingRule.AUTO);
//                XWPFRun run3 = p3.createRun();
//
//                run3.setText("自我评价");
//                run3.setFontSize(11);
//                run3.setBold(true);
//                XWPFParagraph p4 = document.createParagraph();
//                XWPFRun pr4 = p4.createRun();
//                pr4.setFontSize(9);
//                pr4.setText(studentResume.getEvaluation().replaceAll("\\n","\r"));
//            }


            document.write(out);
            out.close();
            log.info("create student resume written success.");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
    }


}
